package com.example.light.common.exception;

import com.example.light.common.result.CodeMsg;
import com.example.light.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice
@RestController
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<String> globalExceptionHandler(Exception e){
        if (e instanceof GlobalException){
            GlobalException ex = (GlobalException) e;
            return Result.error(ex.getCodeMsg());
        }else{
            return Result.error(CodeMsg.SystemCodeMsg.ERROR);
        }
    }
}
